/*fork 子进程 listen port端口,get url ;
 * 等待用户输入url， send url；
 *
 * */
#include"p2p.h"

#define P2P 90  //PROTO
#define BUFFSIZE 1024

struct tasklist{
	uint16_t task;
	uint16_t flag;/*  0, 1, 2*/
	uint32_t host;
	int pfseek;
	int size;
};

struct hostlist{
	uint32_t  host;
	uint16_t  task;
	uint16_t  on; /* 0, 1*/
	int hfseek;
	int size;
};

void initTasklist(struct tasklist *p)
{
	
}


int main(int argc, char **argv)
{
	int i = 3;
	int socksend;
	int reqlen;
	char urlBuff[BUFFSIZE];
	int pid;
	struct sockaddr_in sendaddr;
	struct sockaddr_in recvaddr;
 	struct tasklist[10];
	struct hostlist[20];

	openlog("p2p", LOG_PID, 0);

	pid = fork();
	if(pid < 0){
		perror("can not fork listen process:");
		syslog(LOG_ERR,"fork :%m\n");
		exit(1);
	}else if(pid = 0)
	{
		/* son process*/
		listen_req();

	}else {
		/**/
		printf("please input your url request:\n");
		scanf("%s", urlBuff);
		reqlen = strlen(urlBuff);  /* execpt '\0' */
		
		socksend = socket(AF_INET, SOCK_DGRAM, 0);
		sendaddr.sin_family = AF_INET;
		sendaddr.sin_port = P2P;
		sendaddr.sin_addr = //
		
		initTasklist(tasklist[10], hostlist[20]);// do not finished. if has .conf , get conf file  else  creat it
		
		
		alarm(10);  /* find host erery 10 seconds*/
		if(signal(SIGALRM, sig_guangbo) == SIG_ERR) //do not finished
			perror("signal error:");
		
		while(1){
		updateHostlist(hostlist[]);// do not finished
		}

		
		for(int n = 0; n <= i; n++)
		{
			pushtask(hostlist[]);  // send to hostlist from tasklist[0]if tasklist.flag == 0; 
		}
		pthread()   // check host weather on . if it off & task  , change tasklist's flag to 0,  then cancel host

			
		getdatafromhost(tasklist[]);



	}
		

}















